// Internal action code for project COMP667-Proj

package ca.athabascau.quizmaster.internalactions;

import java.util.ArrayList;
import java.util.Random;

import ca.athabascau.quizmaster.data.Answer;
import ca.athabascau.quizmaster.data.CompleteQuestion;
import ca.athabascau.quizmaster.data.DataAccess;
import jason.asSemantics.*;
import jason.asSyntax.*;

public class getquestion extends DefaultInternalAction {

    /**
	 * 
	 */
	private static final long serialVersionUID = 654486345957678581L;

	@Override
    public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
        // execute the internal action
        ts.getAg().getLogger().info("executing internal action 'ca.athabascau.quizmaster.data.answers'");
        DataAccess da=new DataAccess();
        ts.getAg().getLogger().info(args[0].toString());
        String diff="Easy";//args[0].toString();
      CompleteQuestion cQ=da.getRandomCompleteQuestion(diff);
      
//        question(_questionid,_questiontext,_correctanswernumber,_answer1,_answer2,_answer3,_answer4,_difficulty,_fieldname,_learningobjecttype).
        String question="+question("+ cQ.getAnswer1().getQuestion().getId() + "," +  cQ.getAnswer1().getQuestion().getText()
        						   + ","+ cQ.getAnswer1().getQuestion().getCorrectAnswerNumber() + ","+ cQ.getAnswer1().getAnswerText()
        						   + ","+ cQ.getAnswer2().getAnswerText() + ","+ cQ.getAnswer3().getAnswerText()
        						   + ","+ cQ.getAnswer4().getAnswerText() + ","+ cQ.getAnswer1().getQuestion().getDifficultyLevel().getName()
        						   + ","+ cQ.getAnswer1().getQuestion().getField().getName() + ","+ cQ.getAnswer1().getQuestion().getLearningObjectType().getName() + ")";
        ts.getAg().getLogger().info("question="+question);
        return un.unifies(args[1], new Atom(question));
        
    }
}
